package main

import (
	"gomicro/webGoMicro/webMessage"
	_ "gomicro/webGoMicro/webServer/dao"
	"gomicro/webGoMicro/webServer/handler"
	"log"
	"math/rand"
	"strconv"

	"github.com/micro/go-micro/v2"
	"github.com/micro/go-plugins/registry/etcdv3/v2"
	"github.com/micro/go-plugins/wrapper/ratelimiter/ratelimit/v2"

	juRatelimit "github.com/juju/ratelimit"
	"gomicro/webGoMicro/webServer/wrappers"
)

func main() {
	
	// grpcService := grpc.NewService(
	// 	micro.Name("student_micro_service"),
	// 	micro.Version("v1.18.0"),
	// 	micro.Registry(etcdv3.NewRegistry()),
	// )

	//创建一个新的服务对象实例
	service := micro.NewService(
		micro.Name("student_micro_service"),
		micro.Version("v2.7.0"),
		micro.Registry(etcdv3.NewRegistry()),
		micro.WrapClient(wrappers.NewLogWrapper),//在注册时只需要传入方法名即可，底层会自动给这个方法传入client
		micro.WrapHandler(ratelimit.NewHandlerWrapper(juRatelimit.NewBucketWithRate(float64(2), int64(2)), false)), //限流

		//micro.WrapClient(wrappers.NewClientWrapper()),
	)

	//服务初始化
	service.Init()
	
	// grpcService.Init()

	//注册
	hs := handler.StudentHandlerCuda{
		Tag :strconv.Itoa(rand.Int()),
	}
	webMessage.RegisterStudentServiceHandler(service.Server(), &hs)  //new(handler.StudentHandlerCuda)

	//运行
	err := service.Run()
	if err != nil {
		log.Fatal(err)
	}

	
}
